#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <climits>
#define int long long 
#define x first 
#define y second 
using namespace std ;
typedef pair<int,int> PII;
const int N = 1e5 + 10;
int a[N];
vector<int> cnt;
PII p[N];
map<int,int> mp;
void solve()
{
     int n,k;
     cin >> n >> k;
     for(int i = 1; i <= n; i++) cin >> a[i];
     for(int i = 1; i <= n; i++) mp[a[i]] ++;
     for(auto &c : mp)  cnt.push_back(c.y);
     sort(cnt.begin() , cnt.end() , greater<int>());
     int ans = 0;
     if(k <= mp.size()) 
     {
         cout << k << endl;
         return;
     }
     else  
     { 
         int v = k - mp.size();
      //   cout << v << endl;//2
         int l = 0;
         while(v > 0 && l < mp.size())
         {
            v = v - (cnt[l] - 1);
            l ++ ;
            //k -- ;
         }
       //  cout << v << " " << l << endl;// -1  1
         cout << mp.size() - l << endl;
     }
    /*  样例：
     5 4
     1 1 1 1 99 */

}
signed main()
{
     ios::sync_with_stdio(false);
     cin.tie(nullptr),cout.tie(nullptr);
     int t  = 1 ;
     // cin >> t;
     while(t -- ) solve();
     return 0;
}